<?php
/*
 * Copyright 2004-2005 Sigve Indregard.
 *
 * This file is part of Laivsys.
 *
 * Laivsys is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Laivsys is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Laivsys; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/*
 * $Id: db.php 11 2005-07-11 23:42:55Z say $
 */
require_once("config.php");
require_once("error.php");

//database connection identifier, global variable
$conn=null;

if (! connect() )
	fatalError("Kunne ikke koble til databasen.");

/**
 * Connect to the database specified by the options in config.php.
 * Returns true on success, and false on failure. The global variable $conn is
 * set to the resource identifier on success, and null on failure.
 */
function connect() {
	global $conn;
	$conn=mysql_pconnect(DB_HOST, DB_USER, DB_PASS);
	
	if ($conn === false) {
		$conn=null;
		return false;
	} else {
		$dbselect=mysql_select_db(DB_DATABASE, $conn);
		if (!$dbselect) {
			$conn=null;
			return false;
		} else {
			return true;
		}
	}
}
?>		